"""生成器"""""

'''定义'''
# 特殊的迭代器，但是不需要使用__iter__ 和 __next__
# 使用 yield关键字来取值和暂停

'''仿照range'''


def integer_generator(*args):
    if len(args) == 1:
        end = args[0]
        start = 0
        step = 1
    elif len(args) == 2:
        start = args[0]
        end = args[1]
        step = 1

    elif len(args) == 3:
        start = args[0]
        end = args[1]
        step = args[2]
    else:
        raise ValueError('IntegerIteror需要 1个 或者 2个 或者 3个参数')
    while True:
        yield start
        start += step
        if start >= end:
            break


# print(integer_generator(10)) # <generator object integer_generator at 0x000001ECF4CF04A0>

# for i in integer_generator(2,10,3):
#     print(i)

'''100以内的斐波那契生成器'''


def fib_generator():
    first = 0
    second = 1
    while True:
        yield first
        first, second = second, first + second
        if first >= 100:
            break

for i in fib_generator():
    print(i)